//
//  MyAllBtnView.m
//  Rabbit
//
//  Created by 阿帕 on 2018/11/6.
//  Copyright © 2018年 GCY. All rights reserved.
//

#import "MyAllBtnView.h"

@implementation MyAllBtnView

#pragma mark - Intial
- (instancetype)initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    if (self) {
        
        [self setUpUI];
    }
    
    return self;
}
- (void)dealloc {
    [KNotificationCenter removeObserver:self name:LOGIN_LOGOUT object:nil];
}
- (void)setUpUI {
    WEAKSELF
    self.backgroundColor = [UIColor whiteColor];
    
    [KNotificationCenter addObserver:self selector:@selector(logoutEvent:) name:LOGIN_LOGOUT object:nil];
    
    NSArray *titles = @[@"账户信息", @"银行卡"];
    
    NSArray *values = @[@"0", @"0"];
    
    for (int i=0; i<titles.count; i++) {
        
        UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(ScreenW/titles.count*i, 0, ScreenW/titles.count, self.cy_height)];
        bgView.tag = 100 + i;
        bgView.userInteractionEnabled = YES;
        [bgView nyl_addTapGes:^{
            if (weakSelf.delegate && [weakSelf.delegate respondsToSelector:@selector(getButtonIndex:)]) {
                [weakSelf.delegate getButtonIndex:bgView.tag];
            }
        }];
        [self addSubview:bgView];
        
        UILabel *valueLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 10, ScreenW/titles.count, 30)];
        valueLabel.text = values[i];
        valueLabel.textColor = [UIColor cy_colorWithHexString:@"#434C67"];
        valueLabel.font = font(16);
        valueLabel.tag = 120 + i;
        valueLabel.textAlignment = NSTextAlignmentCenter;
        [bgView addSubview:valueLabel];
        
        UILabel *textLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, valueLabel.bottom, ScreenW/titles.count, 30)];
        textLabel.text = titles[i];
        textLabel.textColor = [UIColor cy_colorWithHexString:@"#434C67"];
        textLabel.font = font(16);
        textLabel.textAlignment = NSTextAlignmentCenter;
        [bgView addSubview:textLabel];
    }
    
    UIView *vLineView = [[UIView alloc] initWithFrame:CGRectMake(ScreenW/2-1, (self.cy_height-25)/2, 1, 25)];
    vLineView.backgroundColor = BackgroundColor;
    [self addSubview:vLineView];
}

- (void)setValueArray:(NSArray *)valueArray {
    
    _valueArray = valueArray;
    
    for (int i=0; i<valueArray.count; i++) {
        UILabel *label = [self viewWithTag:120 + i];
        if (i==0) {
            label.text = CJStringWithFormat(@"%.2f",[_valueArray[i] floatValue]);
        } else {
            label.text = CJStringWithFormat(@"%@",_valueArray[i]);
        }
    }
    
}

- (void)logoutEvent:(NSNotification *)notification {
    
    for (int i=0; i<2; i++) {
        UILabel *label = [self viewWithTag:120 + i];
        label.text = @"0";
    }
    
}
@end
